package com.itheima.controller;


import com.itheima.pojo.User;
import com.itheima.service.UserService;
import com.itheima.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/v1/user")
public class UserController {

    @Autowired
    private UserService userService;

    //根据班级ID查询所有的学生
    @GetMapping("/findByClassId")
    public ResponseResult findByClassId(){
        List<User> byClassId = userService.findByClassId();

        if(byClassId != null){
            return new ResponseResult(0,"操作成功",byClassId);
        }

        return new ResponseResult(1,"操作失败");
    }

    //为用户添加积分
    @PostMapping("/addIntegral")
    public ResponseResult addIntegral(@RequestBody Map<String,Integer> map){
        if(userService.addIntegral(map.get("id"),map.get("integral")))
        {
            return new ResponseResult(0,"操作成功","添加积分成功");
        }else {
            return new ResponseResult(1,"操作失败","添加积分失败");
        }

    }

    @GetMapping("/resetGScoreByGroupId/{classId}")
    public ResponseResult resetGScoreByGroupId(@PathVariable Long classId){
        return userService.resetGScoreByGroupId(classId);

    }

}
